<?php

namespace Navigation;

use Zend\Mvc\MvcEvent;
use Zend\Navigation\Page\Mvc as MvcPage;
use Zend\Navigation\AbstractContainer;

class Module 
{
	
	public function onBootstrap(MvcEvent $e)
	{
		$e->getApplication()
		->getEventManager()
		->attach(
				MvcEvent::EVENT_RENDER,
				function(MvcEvent $e) {
					$user = $e->getApplication()
					->getServiceManager()
					->get('app_navigation');
					
					$auth = $e->getApplication()
					->getServiceManager()
					->get('zfcuser_auth_service');
					
					if ($auth->hasIdentity()) {
						
						$loginPage = $user->findOneByLabel('login');
						$loginPage->setRoute('logout')
						->setLabel('logout');						
					}
					
					
				},
				100
				);
	}
	
	
	
	public function getConfig()
	{
		return include __DIR__ . '/config/module.config.php';
	}
	
	public function getAutoloaderConfig()
	{
		
		return array(
				'Zend\Loader\StandardAutoloader' => array(
						'namespaces' => array(
								__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
								)
						)
				);
		
	}
	
	public function getViewHelperConfig(){
		return array(
				'invokables' => array(
						'ChatHelper' => 'Application\View\Helper\ChatHelper'
				)
		);
	}
	

	
}
